﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using NhaThuocOnline.Entities;
using NhaThuocOnline.Repositories;
using NhaThuocOnline.ViewModels;


namespace NhaThuocOnline.Service
{
    public class ICDService
    {
        public void InsertOrUpdate(ViewModelsICD icd)
        {
            var en = Mapper.Map<ViewModelsICD, ICD>(icd);
            using (ICDRepository repo = new ICDRepository())
            {
                repo.InsertOrUpdate(en);
                repo.Save();
            }
        }
        public void Delete(int id)
        {
            using (ICDRepository repo = new ICDRepository())
            {
                repo.Delete(id);
                repo.Save();
            }
        }
        public List<ViewModelsICD> GetAll()
        {
            using (ICDRepository repo = new ICDRepository())
            {
                return Mapper.Map<List<ICD>, List<ViewModelsICD>>(repo.GetAll.ToList());
            }
        }
        public ViewModelsICD GetICDById(int id)
        {
            using (ICDRepository repo = new ICDRepository())
            {
                return Mapper.Map<ICD, ViewModelsICD>(repo.GetAll.Where(bn => bn.Id == id).FirstOrDefault());
            }
        }
    }
}
